<template>
	<view class="containers">
		<view class="header">
			<view class="header-left">
				<image src="/static/back.png" @click="back" />
				<view class="header-title">
					AI写作
		 	</view>
			</view>
		</view>

		<view class="navbar">
			<!-- 循环出头部tab栏 -->
			<view v-for="(item, index) in navList" :key="index" class="nav-item" @click="handleTabClick(index)"><text
					:class="{ current: tabCurrentIndex === index }">{{
		  item.text
		}}</text></view>
		</view>
		<swiper :current="tabCurrentIndex" class="swiper-box" duration="300" @change="changeTab">
			<swiper-item class="tab-content" v-for="(navItem, navIndex) in navList" :key="navIndex">
				<scroll-view class="list-scroll-content" scroll-y v-if="tabCurrentIndex===0">
					<Creation   :item="info"></Creation>
				</scroll-view>
				<scroll-view class="list-scroll-content" scroll-y v-if="tabCurrentIndex===1">
					<ContinueWrite :item="setting"></ContinueWrite>
				</scroll-view>
			</swiper-item>
		</swiper>
		<!-- <Creation ref="pop" @regodate="regodate" :item="info" style="display: none;"></Creation> -->
		<view class="bottomnav">
			<view class="clear" @click="clear">
				
			</view>
			<button type="primary" plain="true" class="btn" @click="generate">生成</button>

		</view>

	</view>
</template>

<script>
	import topbar from '../../components/top-tabbar/top-tabbar.vue'
	import Creation from '@/pages/Creation/Creation.vue'
	import ContinueWrite from '@/pages/ContinueWrite/ContinueWrite.vue'
	export default {
		data() {
			return {
				setting: {},
				info: {},
				index: 0,
				tabCurrentIndex: 0, //tab栏下标默认为0 未使用
				navList: [
					//每个tab存储的信息
					{
						text: "文章创作",
						loadStatus: "more",
						dataList: [],
						params: {
							memberCouponStatus: "NEW",
							pageNumber: 1,
							pageSize: 10,
							status: 1,
						},
						wheterEmpty: false,
					},
					{
						text: "文章续写",
						loadStatus: "more",
						dataList: [],
						params: {
							memberCouponStatus: "USED",
							pageNumber: 1,
							pageSize: 10,
							status: 2,
						},
						wheterEmpty: false,
					}
				],
				options: {
					top_backgroundcolor: '#ffffff',
					top_itemcolor: '#7d8380',
					top_itemselectcolor: '#455eff'
				},
				tabItem: [{
						name: '中国明星',
						id: 2001
					},
					{
						name: '欧美明星',
						id: 2002
					}
				],
				params: {
					uid: '',
					chat_id: 'new',
					content: '',
					type: 'creation'
				}
			}
		},
		components: {
			topbar,
			Creation,
			ContinueWrite
		},
		onShow() {
			let uid = uni.getStorageSync('uid');
			this.params.uid = uid
		},
		methods: {
			clear() {
				this.$refs.pop.todo();
			},
			back() {
				uni.switchTab({
					url:'../intellectAI/intellectAI'
				})
			},
			handleItemClick(e) {
				console.log(e)
			},
			handleTabClick(index) {
				this.tabCurrentIndex = index;
				// console.log(index);
			},
			/**
			 * 切换tab
			 */
			changeTab(e) {
				this.tabCurrentIndex = e.target.current;
			},
			generate() {
				let continues = uni.getStorageSync('continues');
				let num = uni.getStorageSync('num');
				let creationTitle = uni.getStorageSync('creationTitle');
				let creationKeyWord = uni.getStorageSync('creationKeyWord');
				if (this.tabCurrentIndex == 1) {
					let content = '请接着这段文字续写，字数在' + num + '左右，文字是：' + continues
					if (continues == '' || num == '') {
						uni.showToast({
							icon: 'error',
							title: '请填写内容或字数'
						})
					} else {
						this.params.content = content
						uni.setStorageSync('continueParams', this.params);
						uni.navigateTo({
							url: '../CreationResult/CreationResult'
						})
					}
				} else {
					let content = '请以' + creationTitle + '为主题，写一篇' + num + '字包含以下关键词的文章,关键词是：' + creationKeyWord
					if (creationTitle == '' || num == '' || creationKeyWord == '') {
						uni.showToast({
							icon: 'error',
							title: '请填写全部内容'
						})
					} else {
						this.params.content = content
						uni.setStorageSync('continueParams', this.params);
						uni.navigateTo({
							url: '../CreationResult/CreationResult'
						})
					}
				}

			}
		}
	}
</script>

<style lang="less" scoped>
	.containers {
		// position: relative;
		padding-top: 10px;
	}

	.header {
		display: flex;
		justify-content: space-between;
		height: 100rpx;
		align-items: center;
		width: 100%;
	}

	.header-left {
		display: flex;
		align-items: center;
		padding-left: 30rpx;
	}

	.header-title {
		font-size: 32rpx;
		margin-left: 10rpx;
	}

	.header image {
		width: 45rpx;
		height: 45rpx;
		padding: 10rpx;
	}





	.navbar {
		display: flex;
		height: 100rpx;
		padding: 0 5px;
		background: #fff;
		color: #d5d0eb;
		box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);
		position: relative;
		z-index: 10;

		.nav-item {
			flex: 1;
			height: 100%;
			font-size: 26rpx;
			color: #5750eb;
			position: relative;
			text-align: center;

			text {
				line-height: 80rpx;
			}

			.current {
				font-weight: bold;
				font-size: 28rpx;

				&:after {
					content: "";
					position: absolute;
					bottom: 10rpx;
					left: 40%;
					width: 60rpx;
					border-bottom: 2px solid #5750eb;
				}
			}
		}
	}

	.swiper-box {
		height: calc(100vh - 40px);
	}

	.list-scroll-content {
		height: 100vh;
		width: 100%;

		.coupon-item {
			display: flex;
			align-items: center;
			height: 220rpx;
			margin: 20rpx;

			.left {
				height: 100%;
				width: 260rpx;
				background-color: #5750eb;
				position: relative;

				.message {
					color: blue;
					display: flex;
					justify-content: center;
					align-items: center;
					flex-direction: column;
					margin-top: 40rpx;

					view:nth-child(1) {
						font-weight: bold;
						font-size: 60rpx;
					}

					view:nth-child(2) {
						font-size: 20px;
					}
				}

				.wave-line {
					height: 220rpx;
					width: 8rpx;
					position: absolute;
					top: 0;
					left: 0;
					background-color: #5750eb;
					overflow: hidden;

					.wave {
						width: 8rpx;
						height: 16rpx;
						background-color: #ffffff;
						border-radius: 0 16rpx 16rpx 0;
						margin-top: 4rpx;
					}
				}

				.circle {
					width: 40rpx;
					height: 40rpx;
					background-color: #ccc;
					position: absolute;
					border-radius: 50%;
					z-index: 111;
				}

				.circle-top {
					top: -20rpx;
					right: -20rpx;
				}

				.circle-bottom {
					bottom: -20rpx;
					right: -20rpx;
				}
			}

			.right {
				display: flex;
				justify-content: space-between;
				align-items: center;
				width: 450rpx;
				font-size: 20px;
				height: 100%;
				background-color: #ffffff;
				overflow: hidden;
				position: relative;

				.content {
					color: #666666;
					margin-left: 20rpx;
					line-height: 2em;

					>view:nth-child(1) {
						color: #ff6262;
						font-size: 30rpx;
					}

					.title-1,
					.title-2,
					.title-3 {
						font-size: 25rpx;
					}
				}

				.receive {
					color: #ffffff;
					background-color: #5750eb;
					border-radius: 50%;
					width: 86rpx;
					height: 86rpx;
					text-align: center;
					margin-right: 48rpx;
					vertical-align: middle;
					padding-top: 8rpx;
					position: relative;
					z-index: 2;
				}

				.jiao-1 {
					background-color: #ffc71c;
					width: 400rpx;
					transform: rotate(45deg);
					text-align: center;
					position: absolute;
					color: #ffffff;
					right: -130rpx;
					top: 0;

					.text-1 {
						margin-left: 68rpx;
						font-size: 28rpx;
					}

					.text-2 {
						margin-left: 68rpx;
						font-size: 28rpx;
					}
				}

				.no-icon {
					border-radius: 50%;
					width: 86rpx;
					height: 86rpx;
					margin-right: 48rpx;
					position: relative;
					z-index: 2;
				}

				.bg-quan {
					width: 244rpx;
					height: 244rpx;
					border: 6rpx solid #5750eb;
					border-radius: 50%;
					opacity: 0.1;
					color: #5750eb;
					text-align: center;
					padding-top: 30rpx;
					font-size: 130rpx;
					position: absolute;
					right: -54rpx;
					bottom: -60rpx;
				}
			}
		}
	}

	.bottomnav {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 96%;
		height: 120rpx;
		line-height: 120rpx;
		background-color: #fff;
		padding: 0 2%;

		.clear {
			display: inline-block;
			color: #9d9d9d;
			font-size: 16px
		}

		.btn {
			display: inline-block;
			float: right;
			margin: 20rpx;
			height: 70rpx;
			line-height: 65rpx;

		}
	}
</style>
